package createStream;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Stream;

import static java.util.stream.IntStream.range;

public class StreamOf {
    public static void main(String[] args) {
        // 中间需要传入一组元素参数
         // 代码中传入的是一组字符串元素，forEach() 传入一个方法引用。
        Stream.of("It's ", "a ", "wonderful ", "day ", "for ", "pie!")
            .forEach(System.out::println);

        //集合的stream()
        List<String> list = Arrays.asList("It's a wonderful day for pie!".split(" "));
        list.stream().forEach(System.out::print);

        //生成器
        Stream.generate(() -> "duplicate")
                      .limit(3)
                      .forEach(System.out::println);

        //基本类型流的生成
        System.out.println(range(10, 20).sum());

        //数组流的生成
        Arrays.stream(new double[] { 3.14159, 2.718, 1.618 })
                .forEach(n -> System.out.format("%f ", n));
//
        Stream.of(1, 2, 3)
                .flatMap(i -> Stream.of("Gonzo", "Fozzie", "Beaker"))
                .forEach(System.out::println);

    }
}
